<?php
/**
* Authorization module class file.
*
* @author Christoffer Niska <cniska@live.com>
* @copyright Copyright &copy; 2010 Christoffer Niska
* @version 0.9
*/
class AuthorizationModule extends CWebModule
{
	/**
	* @var string Super user name
	* This variable can be set in module config
	*/
	public $superUser;

	/**
	* @var bool Enable business rules?
	* This variable can be set in module config
	*/
	public $enableBizRule = false;

	/**
	* @var bool Enable data for business rules?
	* This variable can be set in module config
	*/
	public $enableBizRuleData = false;

	/**
	* @var string Current module version
	*/
	public $version = '0.9';

	/**
	* Initialization.
	*/
	public function init()
	{
		// this method is called when the module is being created
		// you may place code here to customize the module or the application

		// import the module-level models and components
		$this->setImport(array(
			'authorization.models.*',
			'authorization.components.*',
			'authorization.controllers.*',
		));

		// Set the authorization component needed by this module
		$this->setComponent('auth', new Authorization);

		// Create the authorization component's role hierarchy
		$this->auth->createHierarchy($this->superUser);

		// Create a map for the authorization component of the assigned items for each role
		$this->auth->createAuthChildMap();

		// Set the default controller
		$this->defaultController = 'main';
	}

	/**
	* @return Authorization component.
	*/
	public function getAuth()
	{
		return $this->getComponent('auth');
	}
}
